package com.xky.service.impl;
/**
 * 员工管理方法
 */

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xky.mapper.EmpMapper;
import com.xky.pojo.Emp;
import com.xky.pojo.PagesBean;
import com.xky.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

//    @Override
//    public PagesBean pages(Integer page, Integer pageSize) {
//        //1、获取总记录数
//       Long count = empMapper.count();
//
//        //2、获取分页查询结果列表
//        Integer start=( page - 1) * pageSize;
//        List<Emp> empList =  empMapper.pages(start,pageSize);
//
//        //封装PageBean对象
//        PagesBean pagesBean=new PagesBean(count,empList);
//        return pagesBean;
//    }


    @Override
    public PagesBean pages(Integer page, Integer pageSize, String name, Short gender,LocalDate begin, LocalDate end,LocalDate entrydate) {
        //1、设置分页参数
        PageHelper.startPage(page,pageSize);

        //2、执行查询
        List<Emp> pages = empMapper.pages(name,gender,begin,end,entrydate);
        Page<Emp> p =(Page<Emp>)pages;

        //封装PageBean对象
        PagesBean pagesBean=new PagesBean(p.getTotal(),p.getResult());
        return pagesBean;
    }

    @Override
    public void deleteselect(List<Integer> ids) {
        empMapper.delete(ids);
    }

    /**
     * 新增员工
     * @param emp
     */
    @Override
    public void addEmployee(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.save(emp);
    }

    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    @Override
    public Emp selectId(Integer id) {
        return empMapper.selectId(id);
    }

    /**
     * 修改员工信息
     *
     * @param emp
     * @return
     */
    @Override
    public Emp update(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
        return null;
    }

}
